import {ADD_TO_SELECTED,DELETE_FROM_SELECTED,MULTIPLE_ADD_TO_SELECTED} from "../actions/selected-actions";

const State = {
    bedroom:[],
    price:[]
};

export default function (state = State, action) {
    let name = action.payload?action.payload.name:'';
    let data = action.payload?action.payload.data:'';
    switch (action.type) {
        case ADD_TO_SELECTED:{
            const obj = {};
            obj[name] = [action.payload.data];
            return Object.assign({},state,obj);
        }
        case DELETE_FROM_SELECTED:{
            const obj = {};
            obj[name] = state[name];
            obj[name].splice(state[name].findIndex((val)=>{
                return Object.is(data,val)
            }),1);
            return Object.assign({},state,obj);
        }
        case MULTIPLE_ADD_TO_SELECTED:{
            const obj = {};
            obj[name] = state[name];
            obj[name].push(data);
            return Object.assign({},state,obj);
        }
        default:
            return state;
    }
}